/*
 * @Author: zi.yang
 * @Date: 2022-02-07 23:51:11
 * @LastEditors: zi.yang
 * @LastEditTime: 2022-02-09 08:28:57
 * @Description: In User Settings Edit
 * @FilePath: \api-generator\app\controller\file.js
 */
'use strict';
const fs = require('fs');
const Controller = require('egg').Controller;

class FileController extends Controller {
  async GetDownloadFileById() {
    const { ctx } = this;
    const result = await ctx.service.file.getFileById(ctx.request.query);
    ctx.attachment(result.data.filepath);
    ctx.set('Content-type', 'application/octet-stream');
    ctx.body = fs.createReadStream(result.data.filepath);
  }
}

module.exports = FileController;
